package com.suixinsanren.design.responsibilitychain.demo02;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class StudentAgeCheck extends AbsCheckStudent {

    private final int AMX_AGE = 60;
    private final int MIN_AGE = 20;

    @Override
    public List<Student> checkStudentInfo(List<Student> studentList) {
        List<Student> checkFailedStudents = studentList.stream().filter(student -> {
            return Objects.isNull(student.getAge()) || student.getAge() >= AMX_AGE || student.getAge() < MIN_AGE;
        }).collect(Collectors.toList());
        System.out.println("年龄检查不通过的学生 = " + checkFailedStudents);
        studentList.removeAll(checkFailedStudents);
        System.out.println("年龄检查通过的学生 = " + studentList);
        return studentList;
    }
}
